import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/', redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../components/Log-in.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../components/Hom-e.vue'),
    redirect: '/shouye',
    children: [{
      path: '/shouye',
      name: 'Shouye',
      component: () => import('../components/Shou-ye.vue')
    },
    {
      path: '/1',
      name: '1',
      component: () => import('../components/department/Depart-ment.vue'),
      children:[
      {
        path:'/xinzeng',
        name:'Xinzeng',
        component:()=>import('../components/department/Xin-zeng.vue')
      },]
    },
    {
      path: '/2',
      name: '2',
      component: () => import('../components/item/It-em.vue')
    },
    {
      path: '/3',
      name: '3',
      component: () => import('../components/project/Pro-ject.vue')
    },
    {
      path: '/4',
      name: '4',
      component: () => import('../components/shiwu/Shi-wu.vue')
    },
    {
      path: '/5',
      name: '5',
      component: () => import('../components/worker/Work-er.vue')
    },
    {
      path: '/6',
      name: '6',
      component: () => import('../components/checkon/Check-on.vue')
    },
    {
      path: '/7',
      name: '7',
      component: () => import('../components/salary/Sala-ry.vue')
    },
    {
      path: '/8',
      name: '8',
      component: () => import('../components/laowuaccounts/Laowu-accounts.vue')
    },
    {
      path: '/9',
      name: '9',
      component: () => import('../components/worknumber/Work-number.vue')
    },
  ]
  }
]

const router = new VueRouter({
  routes
})

//挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to 代表将要要访问的路径
  //from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  // next()放行    next('/login')强制跳转
  if (to.path == '/login') return next()
  //获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})


export default router
